//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.zaicheng.cloud.remotecall.template;

import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Iterator;

public enum CollectionFormat {
    CSV(","),
    SSV(" "),
    TSV("\t"),
    PIPES("|"),
    EXPLODED((String)null);

    private final String separator;

    private CollectionFormat(String separator) {
        this.separator = separator;
    }

    public CharSequence join(String field, Collection<String> values, Charset charset) {
        StringBuilder builder = new StringBuilder();
        int valueCount = 0;
        Iterator var6 = values.iterator();

        while(var6.hasNext()) {
            String value = (String)var6.next();
            if (this.separator == null) {
                builder.append(valueCount++ == 0 ? "" : "&");
                builder.append(UriUtils.encode(field, charset));
                if (value != null) {
                    builder.append('=');
                    builder.append(value);
                }
            } else {
                if (builder.length() == 0) {
                    builder.append(UriUtils.encode(field, charset));
                }

                if (value != null) {
                    builder.append(valueCount++ == 0 ? "=" : UriUtils.encode(this.separator, charset));
                    builder.append(value);
                }
            }
        }

        return builder;
    }
}
